package com.winit.openapi.erp.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.winit.common.spi.context.CommandContext;
import com.winit.erp.spi.bpartner.vo.DeliveryWay;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.model.ResponseMsg;
import com.winit.ups.spi.systemrule.TransportModeService;
import com.winit.ups.spi.systemrule.command.TransportModeCommand;
import com.winit.ups.spi.systemrule.vo.TransportMode;

/**
 * 查询运输方式
 * @author adminchenliu
 *
 */
@Controller
@RequestMapping(value="/erp/delivery")
public class DeliveryWayController extends BaseController {
	private Logger            logger = LoggerFactory.getLogger(DeliveryWayController.class);
	@Resource
	private TransportModeService transportModeService;
    
    @RequestMapping(value="/queryDelivery")
    public String queryDelivery(@ModelAttribute ResponseMsg responseMsg){
    	logger.info("开始查询运输方式");
    	TransportModeCommand command = new TransportModeCommand();
    	TransportMode transportMode = new TransportMode();
    	command.setTransportMode(transportMode);
    	List<TransportMode> tList = transportModeService.getTransportModeList(command);
    	CommandContext ctx = CommandContext.getContext();
    	String language =  ctx.getLanguageCountry();
    	List<DeliveryWay> listDeliveryWay=new ArrayList<DeliveryWay>();
    	for (TransportMode tm : tList) {
    	    DeliveryWay deliveryWay = new DeliveryWay();
    	    deliveryWay.setCode(tm.getTransportModeCode());
    	    if("en_US".equals(language)){
    	        deliveryWay.setName(tm.geteName());
    	    }else{
    	        deliveryWay.setName(tm.getName());
    	    }
    	    deliveryWay.setLanguage(language);
    	    listDeliveryWay.add(deliveryWay);
        }
    	logger.info("查询运输方式有"+listDeliveryWay.size()+"条");
    	responseMsg.setData(listDeliveryWay);
        return SUCCESS;
    }
}
